package com.zhiyou100.review.day002.homework;

/**
 * @packageName: HomeWork2
 * @className: com.zhiyou100.review.day002.homework
 * @Description: TODO 作业二
 * @author: yang
 * @date: 2020/6/2
 */
public class HomeWork2 {
    public static void main(String[] args) {
        printAllWaterFlowerNumber();
    }

    /**
     * @Description: TODO  获取三个数的最大数，最小数，中间数
     * @name: maxAndMinAndMid
     * @param: [a, b, c]
     * @return: void
     * @date: 2020/6/2 7:47 下午
     * @auther: yang
     */
    public static void maxAndMinAndMid(int a, int b, int c) {
        if (a != b && a != c && b != c) {

            if (a > b && a > c) {
                System.out.println("max=" + a);
            }
            if (b > c && b > a) {
                System.out.println("max=" + b);
            }
            if (c > a && c > b) {
                System.out.println("max=" + c);
            }
            if (a > b && a < c || a > c && a < b) {
                System.out.println("mid=" + a);
            }
            if (b > a && b < c || b > c && b < a) {
                System.out.println("mid=" + b);
            }
            if (c > a && c < b || c < a && c > b) {
                System.out.println("mid=" + c);
            }
            if (a < b && a < c) {
                System.out.println("min=" + a);
            }
            if (b < a && b < c) {
                System.out.println("min" + b);
            }
            if (c < a && c < b) {
                System.out.println("min=" + c);
            }
        } else {
            System.out.println("请输入三个不相等的数字");
        }
    }

    /**
     * @Description: TODO  判断是不是质数 true为是，false为不是
     * @name: judgingPrimeNumbers
     * @param: [number]
     * @return: boolean
     * @date: 2020/6/2 7:49 下午
     * @auther: yang
     */

    public static boolean judgingPrimeNumbers(int number) {
        boolean flag = false;
        for (int i = 2; i <= (int) (Math.sqrt(number)); i++) {
            if (number % i == 0) {
                flag = true;
                break;
            }
        }
        return !flag && number != 1;
    }

    /**
     * @Description: TODO  获取所有的水仙花数之和
     * @name: getAllWaterFlowerNumber
     * @param: []
     * @return: int
     * @date: 2020/6/2 7:52 下午
     * @auther: yang
     */

    public static int getAllWaterFlowerNumber() {
        int sum = 0;
        for (int i = 111; i <= 999; i++) {
            int theUnit = i % 10;
            int theDecade = i / 10 % 10;
            int theHundreds = i / 100;
            boolean flag = ((int) (Math.pow(theUnit, 3)) + (int) (Math.pow(theDecade, 3)) + (int) (Math.pow(theHundreds, 3)) == i);
            if (flag) {
                sum += i;
            }
        }
        return sum;
    }

    /**
     * @Description: TODO 打印所有水仙花数
     * @name: printAllWaterFlowerNumber
     * @param: []
     * @return: void
     * @date: 2020/6/2 7:51 下午
     * @auther: yang
     */

    public static void printAllWaterFlowerNumber() {
        System.out.println("水仙花数：");
        for (int i = 111; i <= 999; i++) {
            int theUnit = i % 10;
            int theDecade = i / 10 % 10;
            int theHundreds = i / 100;
            boolean flag = ((int) (Math.pow(theUnit, 3)) + (int) (Math.pow(theDecade, 3)) + (int) (Math.pow(theHundreds, 3)) == i);
            if (flag) {
                System.out.print(i + " ");
            }
        }
        System.out.println();
    }
}
